package com.jeesite.modules.sys.web;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.mybatis.mapper.query.QueryType;
import com.jeesite.common.mybatis.mapper.query.QueryWhere;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.EduTwoOrganizationValues;
import com.jeesite.modules.edu.entity.EduTwoOrganization;
import com.jeesite.modules.sys.entity.EmpUser;
import com.jeesite.modules.sys.entity.Employee;
import com.jeesite.modules.sys.entity.Office;
import com.jeesite.modules.sys.entity.User;
import com.jeesite.modules.sys.service.EmpUserService;
import com.jeesite.modules.sys.service.EmployeeService;
import com.jeesite.modules.sys.service.SystemService;
import com.jeesite.modules.sys.total.UserState;
import com.jeesite.modules.sys.utils.EmpUtils;
import com.jeesite.modules.sys.utils.UserUtils;
@Controller
@RequestMapping(value = "${adminPath}/sys/count")
@ConditionalOnProperty(name = "web.core.enabled", havingValue = "true", matchIfMissing = true)
public class CountController extends BaseController{
	@Autowired
	private SystemService systemService;
	@Autowired
	private EmployeeService employeeService;
	@Autowired
	private EmpUserService empUserService;
	//a:按职称统计：（五类）正高级、副高级、中级、初级、无
	@RequestMapping(value = "totalProfessional")
	@ResponseBody
	public List<Map<String, Object>> totalProfessional(HttpServletRequest request, HttpServletResponse response) {
		User user = UserUtils.getUser();
		String officeCode = null;
		if (!user.getLoginCode().equals("system")) {
			Employee employee = employeeService.get(user.getUserCode());
			if(!StringUtils.isEmpty(employee)) {
				Office office = employee.getOffice();
				if(!StringUtils.isEmpty(office)) {
					officeCode = office.getOfficeCode();
				}
			}
			
		}
		return systemService.totalProfessional(officeCode);
	}
	
	@RequestMapping(value = "total")
	@ResponseBody
	public List<Map<String, Object>> total(HttpServletRequest request, HttpServletResponse response) {
		User user = UserUtils.getUser();
		String officeCode = null;
		if (!user.getLoginCode().equals("system")) {
			Employee employee = employeeService.get(user.getUserCode());
			if(!StringUtils.isEmpty(employee)) {
				Office office = employee.getOffice();
				if(!StringUtils.isEmpty(office)) {
					officeCode = office.getOfficeCode();
				}
				
			}
			
		}

		return systemService.total(officeCode);
	}
	
	/**
	 * 政治面貌
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "totalPolitical")
	@ResponseBody
	public List<Map<String, Object>> totalPolitical(HttpServletRequest request, HttpServletResponse response) {
		User user = UserUtils.getUser();
		String officeCode = null;
		if (!user.getLoginCode().equals("system")) {
			Employee employee = employeeService.get(user.getUserCode());
			if(!StringUtils.isEmpty(employee)) {
				Office office = employee.getOffice();
				if(!StringUtils.isEmpty(office)) {
					officeCode = office.getOfficeCode();
				}
				
			}
			
		}

		return systemService.totalPolitical(officeCode);
	}
	
	@RequestMapping(value = "totalAgeGroup")
	@ResponseBody
	public List<Map<String, Object>> totalAgeGroup(HttpServletRequest request, HttpServletResponse response) {
		User user = UserUtils.getUser();
		String officeCode = null;
		if (!user.getLoginCode().equals("system")) {
			Employee employee = employeeService.get(user.getUserCode());
			if(!StringUtils.isEmpty(employee)) {
				Office office = employee.getOffice();
				if(!StringUtils.isEmpty(office)) {
					officeCode = office.getOfficeCode();
				}
				
			}
			
		}

		return systemService.totalAgeGroup(officeCode);
	}
	
	@RequestMapping(value = "totalTalent")
	@ResponseBody
	public List<Map<String, Object>> totalTalent(HttpServletRequest request, HttpServletResponse response) {
		User user = UserUtils.getUser();
		String officeCode = null;
		if (!user.getLoginCode().equals("system")) {
			Employee employee = employeeService.get(user.getUserCode());
			if(!StringUtils.isEmpty(employee)) {
				Office office = employee.getOffice();
				if(!StringUtils.isEmpty(office)) {
					officeCode = office.getOfficeCode();
				}
				
			}
			
		}

		return systemService.totalTalent(officeCode);
	}
	
	/**
	 * 统计教师数
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "totalTeacher")
	@ResponseBody
	public List<Map<String, Object>> totalTeacher(HttpServletRequest request, HttpServletResponse response) {
		User user = UserUtils.getUser();
		String officeCode = null;
		if (!user.getLoginCode().equals("system")) {
			Employee employee = employeeService.get(user.getUserCode());
			if(!StringUtils.isEmpty(employee)) {
				Office office = employee.getOffice();
				if(!StringUtils.isEmpty(office)) {
					officeCode = office.getOfficeCode();
				}
				
			}
			
		}

		return systemService.totalTeacher(officeCode);
	}
	/**
	 * 办学性质
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "totalHighest")
	@ResponseBody
	public List<Map<String, Object>> totalHighest(HttpServletRequest request, HttpServletResponse response) {
		User user = UserUtils.getUser();
		String officeCode = null;
		if (!user.getLoginCode().equals("system")) {
			Employee employee = employeeService.get(user.getUserCode());
			if(!StringUtils.isEmpty(employee)) {
				Office office = employee.getOffice();
				if(!StringUtils.isEmpty(office)) {
					officeCode = office.getOfficeCode();
				}
				
			}
			
		}

		return systemService.totalHighest(officeCode);
	}
	/**
	 * 导师类型
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "totalMentor")
	@ResponseBody
	public List<Map<String, Object>> totalMentor(HttpServletRequest request, HttpServletResponse response) {
		User user = UserUtils.getUser();
		String officeCode = null;
		if (!user.getLoginCode().equals("system")) {
			Employee employee = employeeService.get(user.getUserCode());
			if(!StringUtils.isEmpty(employee)) {
				Office office = employee.getOffice();
				if(!StringUtils.isEmpty(office)) {
					officeCode = office.getOfficeCode();
				}
				
			}
			
		}

		return systemService.totalMentor(officeCode);
	}
	
	@RequestMapping(value = "level")
	@ResponseBody
	public List<Map<String, Object>> level(HttpServletRequest request, HttpServletResponse response) {
		return systemService.level();
	}
	
	@RequestMapping(value = "nature")
	@ResponseBody
	public List<Map<String, Object>> nature(HttpServletRequest request, HttpServletResponse response) {
		return systemService.nature();
	}
	
	
	/**
	 * 导师类型
	 * @param request
	 * @param response
	 * @return
	 */
	@GetMapping(value = "login")
	public String login(HttpServletRequest request, HttpServletResponse response,Model model) {
		return "modules/sys/login";
	}
	
	@GetMapping(value = "edit")
	public String edit(HttpServletRequest request, HttpServletResponse response,Model model) {
		return "modules/sys/edit";
	}
	
	
	@GetMapping(value = "total")
	public String total(HttpServletRequest request, HttpServletResponse response,Model model) {
		return "modules/sys/total";
	}
	
	
	@PostMapping(value="count")
	@ResponseBody
	public List<UserState> count1(HttpServletRequest request, HttpServletResponse response) {
		User user = UserUtils.getUser();
		String officeCode = null;
		if (!user.getLoginCode().equals("system")) {
			Employee employee = employeeService.get(user.getUserCode());
			if(!StringUtils.isEmpty(employee)) {
				Office office = employee.getOffice();
				if(!StringUtils.isEmpty(office)) {
					officeCode = office.getOfficeCode();
				}
			}
		}
		return employeeService.count(officeCode);
	}
}
